#include "board.h"


#if defined(RT_USING_USER_MAIN) && defined(RT_USING_HEAP)
#define RT_HEAP_SIZE 4096
static uint32_t rt_heap[RT_HEAP_SIZE];     // heap default size: 16K(4096 * 4)
RT_WEAK void *rt_heap_begin_get( void )
{
    return rt_heap;
}

RT_WEAK void *rt_heap_end_get( void )
{
    return rt_heap + RT_HEAP_SIZE;
}
#endif

/**
 * This function will initial your board.
 */
void rt_hw_board_init()
{
    /* 初始化SysTick */
    SysTick_Config( SystemCoreClock / RT_TICK_PER_SECOND );

    /* 硬件BSP初始化统统放在这里，比如LED，串口，LCD等 */

    /* LED 端口初始化 */
//	LED_GPIO_Config();
	GPIO_Config();
	USART_Config();
	USART2_Config();
	//USART3_Config();

    /* Call components board initial (use INIT_BOARD_EXPORT()) */
#ifdef RT_USING_COMPONENTS_INIT
    rt_components_board_init();
#endif

#if defined(RT_USING_USER_MAIN) && defined(RT_USING_HEAP)
    rt_system_heap_init( rt_heap_begin_get(), rt_heap_end_get() );
#endif
}

void SysTick_Handler( void )
{
    /* enter interrupt */
    rt_interrupt_enter();

    rt_tick_increase();

    /* leave interrupt */
    rt_interrupt_leave();
}


void IWDG_Feed_Init( u16 prer, u16 rlr )	
{
	IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);	
	IWDG_SetPrescaler(prer);	
	IWDG_SetReload(rlr);		
	IWDG_ReloadCounter();	
	IWDG_Enable();	
}
void IWDG_Feed(void)
{
	GpioSet(GPIO_WDI,0);
	IWDG_ReloadCounter();	
	GpioSet(GPIO_WDI,1);//外部看门狗，最少1.16秒复位
}
